package com.hundsun.yr.universal.p2p.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;
import com.hundsun.yr.universal.library.widget.HSButton;
import com.hundsun.yr.universal.library.widget.HSEditText;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;

/**
 * Created by xx on 2017/7/19.
 */
public class InvestAmountActivity extends BaseActivity implements View.OnClickListener{
    private HSEditText hset_min_invest_amount;
    private HSEditText hset_max_invest_amount;
    private HSButton btn_sure;
    private String minamount;
    private String maxamount;

    private int SETTINGINVESTAMOUNT = 2;

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return true;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_invest_amount;
    }

    @Override
    protected void initViewsAndEvents() {
        findView();
        toolbar_title.setText(getString(R.string.investment_amount));

        int minamount2 = (int) MathUtils.string2double(minamount);
        int maxamount2 = (int) MathUtils.string2double(maxamount);
        hset_min_invest_amount.setText(minamount2 + "");
        hset_max_invest_amount.setText(maxamount2 + "");
        btn_sure.setOnClickListener(this);
    }

    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.titleBar(R.id.common_toolbar).init();
    }

    public void findView(){
        hset_min_invest_amount = findView(R.id.hset_min_invest_amount);
        hset_max_invest_amount = findView(R.id.hset_max_invest_amount);
        btn_sure = findView(R.id.btn_sure);
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        minamount = extras.getString("minamount");
        maxamount = extras.getString("maxamount");
    }

    @Override
    protected void onEveComming(EventCenter eventCenter) {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return true;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    public void onClick(View view) {
        if (!NetUtils.isNetworkConnected(mContext)){
            showToast(R.string.common_no_network);
            return;
        }

        switch (view.getId()){
            case R.id.btn_sure:
                //判断是否符合条件
                String minamount = hset_min_invest_amount.getText().toString();
                String maxamount = hset_max_invest_amount.getText().toString();
                if (minamount.isEmpty()){
                    showToast("请输入最小投资金额");
                    return;
                }

                if (maxamount.isEmpty()){
                    showToast("请输入最大投资金额");
                    return;
                }

                if (MathUtils.compare(minamount,"1000") < 0){
                    showToast("最小投资金额不能小于1000元");
                    return;
                }

                if (MathUtils.compare(maxamount,"1000000") > 0){
                    showToast("最大投资金额为100万元");
                    return;
                }

                if (MathUtils.compare(minamount,maxamount) > 0){
                    showToast("最小投资金额不能大于最大投资金额");
                    return;
                }

                Intent intent = getIntent();
                intent.putExtra("minamount",minamount);
                intent.putExtra("maxamount",maxamount);
                setResult(SETTINGINVESTAMOUNT,intent);
                finish();
                break;
        }
    }
}
